#!/usr/bin/bash
function merge_media()
{
	audio_filename="$input_audio_name"
	media_filename="$input_media_name"
	output_audio_filename=$(basename "$audio_filename" "-51CTO学堂.mp4").aac
	output_media_filename=$(basename "$media_filename" "-51CTO学堂 (1).mp4")_f.mp4
	/usr/bin/ffmpeg -i "$audio_filename" -acodec copy "$output_audio_filename"  >/dev/null 2>&1
	/usr/bin/ffmpeg -i "$media_filename" -i "$output_audio_filename" -vcodec copy -acodec copy -movflags faststart "${output_media_filename}" >/dev/null 2>&1
	rm -rf "$audio_filename" "$media_filename" "$output_audio_filename"
}

read -p "Please input  file path_number:" input_number 
num_index_0="${input_number: -1}"
count_file=$(ls ${input_number}* |wc -l)
real_count_file=$(expr $count_file / 2)
for i in $(seq 1 $real_count_file)
do
	input_audio_name=$(ls ${input_number}.${i}.*|grep -v "(1)")
	input_media_name=$(ls ${input_number}.${i}.*|grep "(1)")
	merge_media
done




#input_audio_name=$(ls ${input_number}*|grep -v "(1)")
#input_media_name=$(ls ${input_number}*|grep "(1)")
#merge_media
